﻿// ===============================================================================
// Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
// ===============================================================================
using System;
using XCI.Sys.Model;
using XCI.Sys.Service;
using XCI.Windows;

namespace XCI.Sys.Forms
{
    public partial class FrmDicDetails : BaseForm
    {
        public FrmDicDetails(TreeListPlus tree)
        {
            InitializeComponent();
            tabPane.Tree = tree;
        }

        private async void FrmDicDetails_Load(object sender, EventArgs e)
        {
            await tabPane.BindingModelAsync();
        }

        private void BtnClose_Click(object sender, EventArgs e)
        {
            DialogCancel();
        }

        private void TabPane_PageBinding(object sender, DetailsFormPaneBindingEventArgs e)
        {
            e.Task = async () =>
            {
                switch (e.Current.TabPageName)
                {
                    case nameof(tabBasic):
                        var model = await SysDicService.Instance.SelectDicByIdAsync(e.Current.Id);
                        model.DicCategory = await SysDicService.Instance.SelectDicCategoryByCodeAsync(model.Code);
                        bindingSource.DataSource = model;
                        break;
                    case nameof(tabHistoryLog):
                        await historyLogGrid1.LoadAsync(nameof(SysDic), e.Current.Id);
                        break;
                }
            };
        }
    }
}
